package cn.edu.ctbu.bootstraptablepage.service.impl;
import cn.edu.ctbu.bootstraptablepage.domain.Student;
import cn.edu.ctbu.bootstraptablepage.exception.RException;
import cn.edu.ctbu.bootstraptablepage.repository.StudentRepository;
import cn.edu.ctbu.bootstraptablepage.service.IStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

@Service
@Transactional

public class StudentServiceImp implements IStudentService {
    @Autowired
    private StudentRepository studentRepository;
    public Page<Student> getAll(Pageable pageable) {

        return studentRepository.findAll(pageable);
    }

    @Override
    public List<Student> getAll(Example<Student> example) {
        return List.of();
    }

    @Override
    public List<Student> findByName(String studentName) {
        return List.of();
    }

    @Override
    public List<Student> findByNameLike(String studentName) {
        return List.of();
    }

    @Override
    public Student findById(Integer id) {
        return null;
    }

    @Override
    public Student save(Student student) {
        return null;
    }

    @Override
    public void delete(Integer id) {

    }

    @Override
    public void delete(Student student) {

    }

    @Override
    public Page<Student> findAll(Pageable pageable) {
        return null;
    }

    @Override
    public Page<Student> findBySex(Integer sex, Pageable pageable) {
        return null;
    }

    @Override
    public Boolean validUserNameAndPassword(String userName, String password) throws Exception{

        List<Student> students=studentRepository.findByNameAndPassword(userName, password);

        if(students.size()>0){
            //找到用户

            return true;
        }else {
            throw new Exception(RException.REnum.LOGIN_ERR.getMsg());
        }

    }

    @Override
    public List<Student> getAll() {
        return studentRepository.findAll();
    }
}